Package com.nykredit.kundeservice.awt

Source Code of com.nykredit.kundeservice.awt.Print

package com.nykredit.kundeservice.awt;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;

public class Print {
 
   public static void printComponenet(final Component component){
     PrinterJob pj = PrinterJob.getPrinterJob();
     pj.setJobName("Print Component");
     pj.setPrintable (new Printable() {    
       public int print(Graphics pg, PageFormat pf, int pageNum){
         if (pageNum > 0){
           return Printable.NO_SUCH_PAGE;
         }
     
         Graphics2D g2 = (Graphics2D) pg;
         g2.translate(pf.getImageableX(), pf.getImageableY());
         component.paint(g2);

         return Printable.PAGE_EXISTS;
       }
     });
    
     if (pj.printDialog() == false)
       return;
     
     try {
       pj.print();
     } catch (PrinterException ex) {
       // handle exception
     }
   }
}
TOP

Related Classes of com.nykredit.kundeservice.awt.Print

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.